package com.ouc.openplatform.zykt.orderManage.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ouc.openplatform.pojo.EUDataGridResult;
import com.ouc.openplatform.zykt.orderManage.dao.DD_TestItemDao;
import com.ouc.openplatform.zykt.orderManage.dao.DD_TestItem_DetailDao;
import com.ouc.openplatform.zykt.orderManage.model.DD_TestItem;
import com.ouc.openplatform.zykt.orderManage.model.DD_TestItem_Detail;
import com.ouc.openplatform.zykt.orderManage.service.DD_TestItemService;

public class DD_TestItemServiceImpl implements DD_TestItemService {

	private DD_TestItemDao testItemDao;
	private DD_TestItem_DetailDao testItem_DetailDao;

	public DD_TestItem_DetailDao getTestItem_DetailDao() {
		return testItem_DetailDao;
	}

	public void setTestItem_DetailDao(DD_TestItem_DetailDao testItem_DetailDao) {
		this.testItem_DetailDao = testItem_DetailDao;
	}

	public DD_TestItemDao getTestItemDao() {
		return testItemDao;
	}

	public void setTestItemDao(DD_TestItemDao testItemDao) {
		this.testItemDao = testItemDao;
	}

	@Override
	public int insertSelective(DD_TestItem record) {
		return testItemDao.insertSelective(record);
	}

	// 根据专用号和检验项名称查询所有的检验项-----sxl
	@Override
	public EUDataGridResult findAllTestItem(String specialNumber, String testitemName, int page, int rows) {
		// 分页处理
		PageHelper.startPage(page, rows);
		List<DD_TestItem> testItemList = testItemDao.findAllTestItemByCondition(specialNumber, testitemName);
		// 创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(testItemList);
		// 取记录总条数
		PageInfo<DD_TestItem> pageInfo = new PageInfo<DD_TestItem>(testItemList);
		result.setTotal(pageInfo.getTotal());
		return result;
	}

	// 根据产品条码查询所有的检验项-----sxl
	@Override
	public EUDataGridResult findAllTestItemByBarCode(String barCode) {
		// 分页处理
		List<DD_TestItem> testItemList = testItemDao.findAllTestItemByCondition(barCode, null);
		List<DD_TestItem_Detail> testItemDetailList = testItem_DetailDao.findAllDetailByCondition(testItemList.size()>0?testItemList.get(0).getTestitemName():null);
		// 创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(testItemDetailList);
		result.setTotal(testItemDetailList.size());
		return result;
	}

}
